package com.lmy.mySpringboot;

import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;

public class LmySpringApplication {

    //创建tomcat对象并关联spring容器
    public static void run() {
        try {
            //创建tomcat对象
            Tomcat tomcat = new Tomcat();
            //让 tomcat可以将请求转发到spring web容器，因此需要关联
            //"/lmyboot" 就是项目的application context
            //"D:\\IdeaCode\\springboot\\lmySpringboot" 指定项目的目录
            tomcat.addWebapp("/lmyboot", "D:\\IdeaCode\\springboot\\lmySpringboot");
            //设置9090端口
            tomcat.setPort(9090);
            //启动，就会在9090端口监听
            tomcat.start();
            System.out.println("========9090等待请求接入========");
            tomcat.getServer().await();
        } catch (LifecycleException e) {
            throw new RuntimeException(e);
        }
    }
}
